﻿
using Epicor.Pub;
using Ice.Lib.App;
using Ice.Lib.Framework;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Diagnostics;
using System.Reflection;
using System.Windows.Forms;
using Erp.Adapters;
using Ice.Lib.Searches;

namespace Test
{
    public partial class Form1 : Form
    {
        public DataTable dt = new DataTable();
        public string[]  arr = { "123","qwe","dfd"};
        Ice.Core.Session se = null;
        public Form1() 
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            dt.Columns.Add("Col1");
            dt.Columns.Add("Col2");
            dt.Columns.Add("Col3");
            DataRow dr1 = dt.NewRow();
            dr1["Col1"] = "aaa";
            dr1["Col2"] = "bbb";
            dr1["Col3"] = "ccc";
            dt.Rows.Add(dr1);
            DataRow dr2 = dt.NewRow();
            dr2["Col1"] = "111";
            dr2["Col2"] = "222";
            dr2["Col3"] = "333";
            dt.Rows.Add(dr2);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            se = PubFun.Login(@"D:\Program\Epicor\ERP10.1Client\Client\config\Demo1015.sysconfig", PubData.Server_UserID, PubData.Server_Password);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            //PubFun.IMEInit(this);
        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {

        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (se != null)
                label1.Text = "已登录,UserID=" + se.UserID + ",CompanyID=" + se.CompanyID;
            else label1.Text = "未登录";
            //if (PubFun.IMEIsStart())label2.Text = "工具已启动";
            //else label2.Text = "工具未启动";

            if (dt != null) label4.Text = "获取" + dt.Rows.Count.ToString() + "行数据!";
        }

        private void button3_Click(object sender, EventArgs e)
        {
            if (se != null)
            {
                ILauncher IL = new ILauncher(se);
                EpiTransaction otrans = new EpiTransaction(IL);
                PubFun.OpenMenu(otrans, "SE000001");//需要放在Epicor客户端目录下
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            Ice.Core.Session se1 = PubFun.Login(@"D:\Program\Epicor\ERP10.1Client\Client\config\Demo1015.sysconfig", "3510167", "52126070");
            if (se1 != null)
            {
                ILauncher IL = new ILauncher(se1);
                EpiTransaction otrans = new EpiTransaction(IL);
                Epicor.Pub.BAQWhereItem[] queryWhere = new Epicor.Pub.BAQWhereItem[] {
                    new Epicor.Pub.BAQWhereItem("POHeader", "PONum", "5","int","",">") { Seq=1 }
                };
                dt = PubFun.GetBAQData(otrans, "POQuery", true, queryWhere);
            }
        }

        private void button5_Click(object sender, EventArgs e)
        {
            //测试调用快速搜索
            if (se != null)
            {
                ILauncher IL = new ILauncher(se);
                EpiTransaction otrans = new EpiTransaction(IL);
                PubFun.OpenQuickSearchForm(otrans, "BaseDataQuery");
            }

        }

        private void button6_Click(object sender, EventArgs e)
        {
            //添加物料仓库
            if (se != null)
            {
                try
                {
                    ILauncher IL = new ILauncher(se);
                    EpiTransaction otrans = new EpiTransaction(IL);
                    PubFun.NewPartWhse(otrans, "123", "WIP");
                }
                catch (Exception e1) {
                    MessageBox.Show(e1.Message);
                }
            }
        }

 


        ////获取方法
        //public static string GetVarName(System.Linq.Expressions.Expression<Func<string, string>> exp)
        //{
        //    return ((System.Linq.Expressions.MemberExpression)exp.Body).Member.Name;
        //}
    }
}
